/*
 * MasterBot.h
 *
 *  Created on: Nov 18, 2008
 *      Author: nathan
 */

#ifndef MASTERBOT_H_
#define MASTERBOT_H_

#include <QtCore>
#include <QtNetwork>
#include "BncsClient.h"
#include "ServiceAddress.h"

struct BnetServerInfo;
struct BnetClientInfo
{
	BnetServerInfo* server;
	BncsClient* client;
	QString channel;
};

class MasterBot;
struct BnetServerInfo
{
	MasterBot* owner;

	QString host;
	quint16 port;

	QHash<QString /* username */, BnetClientInfo*> chat_bots;
	QList<BnetClientInfo*> game_bots;
	QList<BnetClientInfo*> free_game_bots;
};

class MasterBot : public QObject
{
	Q_OBJECT;

	private:
		QHash<QString /* host:port */, BnetServerInfo*> bncs_table;

		QString lastError;

	public:
		MasterBot(QObject* parent);
		//~MasterBot(void);

	public:

		/* Slave bot registration. */
		bool registerBncsBot(ServiceAddress server);
		bool registerW3gsBot(ServiceAddress server);

		QList<ServiceAddress> getRegisteredBncsBots();
		QList<ServiceAddress> getInactiveBncsBots();
		QList<ServiceAddress> getActiveBncsBots();

		QList<ServiceAddress> getRegisteredW3gsBots();
		QList<ServiceAddress> getInactiveW3gsBots();
		QList<ServiceAddress> getActiveW3gsBots();

		bool unregisterBncsBot(ServiceAddress server, QString user);
		bool unregisterW3gsBot(ServiceAddress server, QString user);

		/* Chat bot controls. */
		bool sendChatAllBots(QString message);
		bool sendChatAllChannels(QString message);
		bool sendChatAllGames(QString message);
		bool sendChatAllServerChannels(ServiceAddress server, QString message);
		bool sendChatAllServerGames(ServiceAddress server, QString message);
		bool sendChatOneChannel(ServiceAddress server, QString channel, QString message);
		bool sendChatOneGame(QString game, QString message);
		bool sendChatOneUser(ServiceAddress server, QString user, QString message);

		/*
		bool createGameAllServers(QString name, WarcraftMapInfo map, WarcraftMapSettings settings);
		bool createGameMultpleServers(QString name, WarcraftMapInfo map, WarcraftMapSettings settings, QStringList servers);
		bool createGameOneServer(QString name, WarcraftMapInfo map, WarcraftMapSettings settings, QString server);
		*/


		/* bool destroyGame(QString name); */


		QString getLastError(void);

	signals:
		void joinChannel(QString server, QString user, QString channel, bool existing);
		void chatChannel(QString server, QString user, QString channel, QString message);
		void leaveChannel(QString server, QString user, QString channel);
		void chatWhisper(QString server, QString user, QString message);

		void joinGame(QString game, QString server, QString user);
		void chatGame(QString game, QString server, QString user);
		void leaveGame(QString game, QString server, QString user);

	private slots:
		/*
		void onBncsLoginStarted(BncsClient* client);
		void onBncsLoginAborted(BncsClient* client, QString reason);
		void onBncsLoginComplete(BncsClient* client);
		void onBncsJoin(BncsClient* client, QString user, QStringList flags, bool existing);

		void onBncsChat(BncsClient* client, QString user, QString text);
		//void onGameChat(WarcraftGameServer* server, QString user, QString text);
		*/
};


#endif /* MASTERBOT_H_ */
